const DEFAULT_TODO_LIST 		= "ToDos"
const FILE_TODO_LISTS 			= "todo_list.dat";

function TodoList( todoListID, todoListTitle )
{
	this.ID 			= todoListID || unique_id( );
	this.title 			= todoListTitle || DEFAULT_TODO_LIST;

	this.saveToFile = function( )
	{
		Log.debug( 'Todo Id'+ this.ID + ' saved to file.' );
		var isNew = true;
		var file = IO.file_get_contents( FILE_TODO_LISTS ).split( NL );
		for ( var i = 0; i < file.length; i++ )
		{
			if( file[i].indexOf( this.ID ) != -1 )
			{
				file[i] = this.toString( );
				isNew = false;	
				break;
			}
		}
		if( isNew )
		{
			file.push( this.toString( ) );
		}
		return IO.file_put_contents( file.join( NL ), FILE_TODO_LISTS );
	}
	
	this.toString = function( )
	{
		var str = this.ID + DELIMITER;
    	str += this.title;
    	return str;
	}
	
	return this;
}

function tdt_getTodoLists( ) 
{
	var aTodoLists = [];
	var file = IO.file_get_contents( FILE_TODO_LISTS ).split( NL );
	
	for ( var i = 0; i < file.length; i++ )
	{
		var line = file[i];
		if( line == '' ) continue;

		aTodoLists.push( line.split( DELIMITER ) );
	}
	return aTodoLists;
}